package com.znf4.controller.good;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.znf4.base.BaseReturnModel;
import com.znf4.good.specs.entity.Specs;
import com.znf4.good.specs.server.SpecsServer;

/**
 * 账户信息 
 */
@RestController
@RequestMapping("/good/specs")
public class SpecsController {
	
	@Autowired
	private SpecsServer specsServer ;
	

	/**
	 * 函数功能说明 ： 添加农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> add(Specs specs ) {
		
		specsServer.addGoodSpecs(specs);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	
	
	/**
	 * 函数功能说明 ： 修改农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> update(Specs specs ) {
		
		specsServer.updateGoodSpecs(specs);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	/**
	 * 函数功能说明 ： 删除农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delOne(Specs specs ) {
		
		specsServer.delOneGoodSpecs(specs);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	/**
	 * 函数功能说明 ： 删除多条农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delAll(String[] ids) {
		
		List<Specs> list = new ArrayList<>() ;
		for(int i=0 ; i < ids.length ; i ++ ){
			Specs spec = new Specs() ;
			spec.setId(ids[i]);
			list.add(spec) ;
		}
		specsServer.delAllGoodSpecs(list);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}
	

	/**
	 * 函数功能说明 ： 获取农作物所有的规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> queryAll(Specs specs) {
		
		List<Specs> list = specsServer.queryAll(specs);
		
		return BaseReturnModel.getMapModel("success", list , "");
	}
	
	

}
